package com.lkd.controller;

import com.lkd.dto.UserDTO;
import com.lkd.entity.User;
import com.lkd.result.TableInfo;
import com.lkd.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Z.lx
 * @Date: 2025/8/19 20:41
 * @Description:
 **/
@RestController
@RequestMapping("/api/user-service/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/search")
    public TableInfo<User> list(UserDTO userDTO){
        log.info("用户列表搜索:{}",userDTO);
        return userService.list(userDTO);
    }
    /**
     * 新增用户
     */
    @PostMapping
    public Boolean add(@RequestBody User user){
        return userService.add(user);
    }
    /**
     * 修改用户
     */
    @PutMapping("/{id}")
    public Boolean update(@PathVariable Long id,@RequestBody User user){
        user.setId(id);
        return userService.update(user);
    }
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Long id){
        return userService.delete(id)>0;
    }
}
